package proxy.model;

import java.io.Serializable;

import org.apache.commons.codec.binary.Base64;

public class User implements Serializable{
	private static final long serialVersionUID = 2491013869973600169L;
	
	public String username;
	public String password;
	
	public User(){
		
	}
	
	public User(String username, String password){
		this.username = username;
		this.password = password;
	}
	
	public int hashCode(){
		return username.hashCode() ^ password.hashCode();
	}
	
	public boolean equals(Object object){
		boolean ret = false;
		if (object instanceof User){
			User user = (User) object;
			if (username.equals(user.username) && password.equals(user.password)){
				ret = true;
			}
		}
		return ret;
	}
	
	public String toString(){
		return username + " : " + password;
	}
	
	public String getBasicAuthentication(){
		return Base64.encodeBase64String((username + ":" + password).getBytes());
	}
	
	public String[] getTableValues(){
		return new String[]{"", username, password.replaceAll("[^*]", "*")};
	}
}
